package com.xwj.validation.custom.controller;

import com.alibaba.fastjson.JSON;
import com.xwj.common.util.R;
import com.xwj.validation.custom.dto.StudentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xiaowajiang
 * @Date: 2022-03-17 22:23
 * @Description: 自定义校验注解
 **/
@Slf4j
@RestController
@Api(value = "CustomValidController", tags = "自定义校验注解")
public class CustomValidController {

    @ApiOperation(value = "请求体中发送 JSON 数据", notes = "校验失败后，抛出 MethodArgumentNotValidException 异常")
    @PostMapping("custom/valid/student/save")
    public R save(@Validated @RequestBody StudentDTO stu) {
        log.info("保存学员信息，入参：{}", JSON.toJSONString(stu));
        // 业务逻辑
        return R.ok();
    }

}
